package com.woniuxy.automotivemanagementsystem.controller;

import com.woniuxy.automotivemanagementsystem.entity.Orders;
import com.woniuxy.automotivemanagementsystem.entity.vo.OrdersVo;
import com.woniuxy.automotivemanagementsystem.service.OrdersService;
import com.woniuxy.automotivemanagementsystem.utils.IdDto;
import com.woniuxy.automotivemanagementsystem.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    /*
    * 创建订单接口
    * */
    @PostMapping("/create")
    public Result create(@RequestBody Orders orders){
        return ordersService.create(orders);
    }
    /*
    * 所有订单菜单中的条件查询所有方法
    * */
    @PostMapping("/queryCondition")
    public Result queryCondition(@RequestBody OrdersVo ordersVo){
        return ordersService.queryCondition(ordersVo);
    }
    /*
    * 我的订单中条件查询所有方法
    * */
    @PostMapping("/myOrdersQueryCondition")
    public Result myOrdersQueryCondition(@RequestBody OrdersVo ordersVo){
        return ordersService.queryCondition(ordersVo);
    }
    /*
    * 单个订单打回接口
    * */
    @PostMapping("/reject")
    public Result reject(@RequestBody IdDto dto){
        if(dto==null){
            return Result.error("参数错误");
        }
        return ordersService.reject(dto.getId());
    }
    /*
    * 单个订单审批通过接口
    * */
    @PostMapping("/approve")
    public Result approve(@RequestBody IdDto dto){
        if(dto==null){
            return Result.error("参数错误");
        }
        return ordersService.approve(dto.getId());
    }
    /*
    * 订单批量审批通过接口
    * */
    @PostMapping("/batchApprove")
    public Result batchApprove(@RequestBody IdDto dto){
        if(dto==null){
            return Result.error("参数错误");
        }
        return ordersService.batchApprove(dto.getIds());
    }
    /*
    * 订单批量审批不通过接口
    * */
    @PostMapping("/batchReject")
    public Result batchReject(@RequestBody IdDto dto){
        if(dto==null){
            return Result.error("参数错误");
        }
        return ordersService.batchReject(dto.getIds());
    }
    /*
    * 还车接口
    * */
    @PostMapping("/returnCar")
    public Result returnCar(@RequestBody IdDto dto){
        if(dto==null){
            return Result.error("参数错误");
        }
        ordersService.lambdaUpdate()
                .eq(Orders::getOid,dto.getId())
                .set(Orders::getStatus,3)
                .update();
        return Result.success("还车成功");
    }
}
